package com.yegs.jltqc.controller;

import com.yegs.jltqc.TO.NamePageQuery;
import com.yegs.jltqc.VO.RpProduce;
import com.yegs.jltqc.VO.RpStock;
import com.yegs.jltqc.config.Msg;
import com.yegs.jltqc.service.RpProduceService;
import com.yegs.jltqc.service.RpStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rpStock")
public class RpStockController {

    @Autowired
    private RpStockService rpStockService;

    @PostMapping("/save")
    public Msg save(@RequestBody RpStock rpStock){
        try{
            rpStockService.save(rpStock);
            return Msg.success("保存成功!");
        }catch (Exception e){
            return Msg.error(e.getMessage());
        }
    }

    @GetMapping("/list")
    public Msg list(){
        return Msg.success("list",rpStockService.list());
    }

    @GetMapping("/get")
    public Msg get(@RequestParam Long id){
        return Msg.success("data", rpStockService.get(id));
    }
    @GetMapping("/del")
    public Msg del(@RequestParam Long id){
        rpStockService.del(id);
        return Msg.success();
    }
    @GetMapping("/getLast")
    public Msg getLast(@RequestParam(required = false) Long id){
        return Msg.success("data",rpStockService.getLast(id));
    }
    @GetMapping("/getNext")
    public Msg getNext(@RequestParam(required = false) Long id){
        return Msg.success("data",rpStockService.getNext(id));
    }

    @PostMapping("/query")
    public Msg query(@RequestBody NamePageQuery query){
        return Msg.success("page",rpStockService.query(query));
    }




}
